package com.zhongyu.order.consumer.config;

import com.zhongyu.comm.util.Constants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    @Bean
    public DirectExchange orderCreateExchange(){
    return ExchangeBuilder.directExchange(Constants.RabbitExchangeName.ORDER_CREATE_EXCHANGE)
            .durable(true).build();
    }

   /* @Bean
    public DirectExchange dlxOrderPayExchange(){
      return ExchangeBuilder.directExchange(Constants.RabbitExchangeName.DLX_ORDER_PAY_EXCHANGE)
          .durable(true).build();
    }*/
    @Bean
     public Queue orderAddQueue(){
        return QueueBuilder.durable(Constants.RabbitQueueName.ORDER_ADD_QUEUE).build();
     }
    @Bean
     public Queue orderPayQueue(){
        return QueueBuilder.durable(Constants.RabbitQueueName.ORDER_PAY_QUEUE).ttl(1000*60*20).build();
     }
   /* @Bean
     public Queue dlxOrderPayQueue(){
        return QueueBuilder.durable(Constants.RabbitQueueName.DLX_ORDER_PAY_QUEUE).build();
     }*/
    @Bean
     public Binding orderAddBinding(){
        return BindingBuilder.bind(orderAddQueue())
                .to(orderCreateExchange())
                .with(Constants.RabbitRoutingKey.ORDER_CREATE);
     }
    @Bean
     public Binding orderPayBinding(){
        return BindingBuilder.bind(orderPayQueue())
                .to(orderCreateExchange())
                .with(Constants.RabbitRoutingKey.ORDER_CREATE);
     }

}
